SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE view [dbo].[otraajustes] as 
SELECT     a.apellidos, a.nombres, a.documento, i.aniolectivo, o.nombre, o.cuise, i.curso
FROM         tb_inscripciones i INNER JOIN
                      tb_alumnos a ON a.idalumno = i.alumno INNER JOIN
                      tb_organizaciones o ON o.idorganizaciones = i.organizacion
WHERE     i.alumno NOT IN
                          (SELECT     alumno
                            FROM          tb_alumnodivision
                            WHERE      aniolectivo in(2010,2009)) AND aniolectivo in(2010--,2009
) AND a.apellidos IS NOT NULL
UNION
SELECT     a.apellidos, a.nombres, a.documento, ad.aniolectivo, o.nombre, o.cuise, dt.curso
FROM         tb_alumnodivision ad INNER JOIN
                      tb_alumnos a ON a.idalumno = ad.alumno INNER JOIN
                      tb_divisionestemp dt ON dt.iddivision = ad.division INNER JOIN
                      tb_organizaciones o ON o.cuise = dt.cuise
WHERE     aniolectivo in(2010--,2009
) AND a.apellidos IS NOT NULL




GO
